<template>
  <div
    class="main-box"
    :style="{
      width:
        configOption.JE_SYS_LOGINMETHOD == loginPlan.MARK_LOGIN_LOGINMETHOD_1 ? '360px' : '360px',
    }"
  >
    <div v-show="curLoginWay == loginWay.LOGIN_WAY_ACCOUNT">
      <login-account />
    </div>
    <div v-show="curLoginWay == loginWay.LOGIN_WAY_FAST">
      <login-fast />
    </div>
  </div>
</template>

<script>
  import { defineComponent, toRefs, ref, nextTick, onMounted, onUnmounted } from 'vue';
  import { LOGIN_WAY, EVENT_METHOD, LOGIN_PLAN } from '@/helper/constant';
  import VueEvent from '@/helper/event';
  import LoginAccount from '@/views/login/components/login-account.vue';
  import LoginFast from '@/views/login/components/login-fast.vue';
  export default defineComponent({
    name: 'LoginMain',
    components: {
      LoginAccount,
      LoginFast,
    },
    setup() {
      let curLoginWay = ref(LOGIN_WAY.LOGIN_WAY_ACCOUNT);
      let configOption = ref({ JE_SYS_LOGINMETHOD: LOGIN_PLAN.MARK_LOGIN_LOGINMETHOD_1 });
      const state = {
        loginWay: LOGIN_WAY,
        loginPlan: LOGIN_PLAN,
        eventMethod: EVENT_METHOD,
      };
      const methods = {
        changeLoginWay(data) {
          nextTick(() => {
            //监听登录方式改变
            curLoginWay.value = data;
          });
        },
        triggerConfig(data) {
          nextTick(() => {
            //监听登录页面配置信息
            // configOption.value = data;
            configOption.value = { ...data };
          });
        },
      };
      //监听事件
      onMounted(() => {
        VueEvent.on(state.eventMethod.LOGIN_METHOD, methods.triggerConfig);
        VueEvent.on(state.eventMethod.LOGIN_WAY, methods.changeLoginWay);
      });
      onUnmounted(() => {
        VueEvent.off(state.eventMethod.LOGIN_METHOD);
        VueEvent.off(state.eventMethod.LOGIN_WAY);
      });

      return {
        curLoginWay,
        configOption,
        ...toRefs(state),
        ...methods,
      };
    },
  });
</script>
<style scoped lang="less">
  .main-box {
    width: 360px;
    // height: 274px;
    margin: 20px auto 0;
    .input-item {
      border-radius: 2px;
      font-size: 12px;
      color: #a1a1a1;
      line-height: 46px;
      height: 46px;
    }
  }
  .operate-box {
    width: 100%;
    height: 20px;
    display: flex;
    justify-content: end;
    margin-top: 20px;
    font-size: 14px;
    color: #3f3f3f;
    .opera-item {
      padding-right: 8px;
    }
    .sepa-line {
      color: #dcdfe6;
      padding-right: 8px;
    }
  }
  .err-tip {
    width: 100%;
    height: 20px;
    margin-top: 30px;
    line-height: 20px;
    font-size: 14px;
    color: #ff625c;
    text-align: center;
  }
  .login-btn {
    height: 42px;
    margin-top: 10px;
    background: #3265f5;
    font-size: 18px;
    color: #ffffff;
    line-height: 20px;
  }
</style>
